package com.github.chirspan.xaas.auth.integration.authenticator;

import cn.hutool.core.util.StrUtil;
import com.github.chirspan.xaas.auth.integration.IntegrationAuthentication;
import com.github.chirspan.xaas.security.service.AuthUserDetail;
import com.github.chirspan.xaas.security.service.UserAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
 * *******description*******
 * 默认用户名密码登录处理
 * *************************
 *
 * @author ChenPan
 * @date 2019/3/29 09:18
 */
@Component
@Primary
public class UsernamePasswordAuthenticator extends AbstractPreparableIntegrationAuthenticator {

    @Autowired
    private UserAuthService userAuthService;

    @Override
    public AuthUserDetail authenticate(IntegrationAuthentication integrationAuthentication) throws Exception {
        AuthUserDetail userAuth = userAuthService.loadUserByUsername(integrationAuthentication.getUsername());
        return userAuth;
    }

    @Override
    public void prepare(IntegrationAuthentication integrationAuthentication) {

    }

    @Override
    public boolean support(IntegrationAuthentication integrationAuthentication) {
        return StrUtil.isEmpty(integrationAuthentication.getAuthType());
    }


}